package com.bjc.base.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.bean.menu.WxMenuButton;
import me.chanjar.weixin.mp.api.WxMpService;

/****
 * 菜单配置
 * 
 * @author admin
 *
 */
@Configuration
@Slf4j
public class WxMenuConfig {

	@Value("${myserver.url}")
	private String myserverUrl;
	/***
	 * 创建菜单
	 * @param wxService
	 * @return
	 */
	public WxMenu getMenu(WxMpService wxService) {
		String url11 = myserverUrl + "/scanRead.html";
		String OAuth2url11 = wxService.oauth2buildAuthorizationUrl(url11, WxConsts.OAuth2Scope.SNSAPI_USERINFO, null);
		String url12 = myserverUrl + "/back.html";
		String OAuth2url12 = wxService.oauth2buildAuthorizationUrl(url12, WxConsts.OAuth2Scope.SNSAPI_USERINFO, null);
		String url13 = myserverUrl + "/index.html";
		String OAuth2url13 = wxService.oauth2buildAuthorizationUrl(url13, WxConsts.OAuth2Scope.SNSAPI_USERINFO, null);
		
		
		log.info("第1个菜单：" + url11);
		log.info("第2个菜单：" + url12);
		log.info("第3个菜单：{}", url13);
		
		WxMenu menu = new WxMenu();
		WxMenuButton button1 = new WxMenuButton();
		button1.setType(WxConsts.MenuButtonType.VIEW);
		button1.setUrl(OAuth2url11);
		button1.setName("借");

		WxMenuButton button2 = new WxMenuButton();
		button2.setType(WxConsts.MenuButtonType.VIEW);
		button2.setUrl(OAuth2url12);
		button2.setName("还");

		WxMenuButton button3 = new WxMenuButton();
		button3.setType(WxConsts.MenuButtonType.VIEW);
		button3.setUrl(OAuth2url13);
		button3.setName("绘﹒享");

		menu.getButtons().add(button1);
		menu.getButtons().add(button2);
		menu.getButtons().add(button3);
//
//		
//			
//		WxMenuButton button11 = new WxMenuButton();
//		button11.setType(WxConsts.MenuButtonType.VIEW);
//		button11.setName("我要借书");
//		button11.setUrl(OAuth2url11);
//		WxMenuButton button12 = new WxMenuButton();
//		button12.setType(WxConsts.MenuButtonType.VIEW);
//		button12.setName("绘本书城");
//		button12.setUrl(OAuth2url12);
//
//
//		button1.getSubButtons().add(button11);
//		button1.getSubButtons().add(button12);

		return menu;
	}

}
